<html>
<head>
<title>JSON test Drupal site</title>
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-sha256.js"></script>
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-crypto-md5.js"></script>
<script type="text/javascript" src="http://crypto-js.googlecode.com/files/2.2.0-hmac-min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" >
var JSON_SERVER_URL = "http://soatest.dpdk.nl/soanl/services/json";
//var JSON_SERVER_URL = "http://www.soatest.nl/soanl/services/json";
var JSON_SERVER_APIKEY = "2dcdc3b0fba51b93719873769efcd473";
//var JSON_SERVER_APIKEY = "7bef4be28e934f0d82b3f698134bc9fb";
var JSON_SERVER_DOMAIN = "mobile";
var JSON_SERVER_SESSID = null;

/**
 * Function apperently neccesary to convert drupal json string to real json object
 */
function dataToJSON(data){
	data = data.replace(/\\x3c/ig, "<");
	data = data.replace(/\\x3e/ig, ">");
	data = data.replace(/\\x26/ig, "&");
	data = data.replace(/\\'/ig, "'");
	return JSON.parse(data);
}

function systemConnect(){
    $.post(
    		JSON_SERVER_URL,
            {"method": "system.connect"},
            function(data)
            {
                response = dataToJSON(data);
    			sessid = response["#data"].sessid;
                JSON_SERVER_SESSID = sessid;

                // do some test function
                doJSONCall('soatest.findSOAPoli', {
                        								"streetCityName": "Calandstraat 5a, Rotterdam",
                        								"distance":"all"
												  });
      		}
    	);
}

/*
 * Generic call method
 */
function doJSONCall(method, data){
	var domain_time_stamp = Math.round((new Date()).getTime() / 1000);
	var nonce = Crypto.MD5(Math.random() + ";" + domain_time_stamp);
	var hstring = domain_time_stamp + ';' + JSON_SERVER_DOMAIN + ';' + nonce + ';' + method;
	var hash = Crypto.HMAC(Crypto.SHA256, hstring, JSON_SERVER_APIKEY);

	$.post(	
		JSON_SERVER_URL,
        {
        	"hash": hash,
        	"method": method, 
        	"domain_name": JSON_SERVER_DOMAIN,
        	"domain_time_stamp": domain_time_stamp,
        	"nonce": nonce,
        	"sessid": JSON_SERVER_SESSID, 
        	"data": data
        },
        function(data)
        {
            response = dataToJSON(data);
            console.log(response);
            // do something
        }
	);
}


$(document).ready(		
		function()
		{
			systemConnect();
		}
);
</script>


</head><body>Test js (check console)
<!--
Make sure the json_server.module has a properly working json_decode, because this method fails for simple data in some PHP5 versions:

quick fix:
ction drupal_parse_json($v) {
  // PHP 5 only
  // @dpdk Tom removed the json_decode, because it turns strings into NULL since version > 5.2.6 (see comments on http://php.net/manual/en/function.json-decode.php)
  if (function_exists('json_decode')) {
    $rv =  json_decode($v);
    if(!$rv)
    {
        $rv = $v;
        if ($v{0} == '"') {
            $v = substr($v, 1, -1);
        }
    }
    return $rv;
  }
  
  and: 
  make sure the json_server is the most recent 
 -->
</body>
</html>